package at.horario.web;

import at.horario.service.LoadDataManager;
import at.horario.web.pages.*;
import org.apache.wicket.authentication.AuthenticatedWebApplication;
import org.apache.wicket.authentication.AuthenticatedWebSession;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import static org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext;


public class HorarioApplication extends AuthenticatedWebApplication {

    public void init() {

        super.init();
        getDebugSettings().setAjaxDebugModeEnabled(true);
        getMarkupSettings().setStripWicketTags(true);
        getResourceSettings().setThrowExceptionOnMissingResource(false);


        springInjection();
        // make bookmarkable pages for easy linking from Menu/SiteMesh
        mountBookmarkablePage("/login.html", Login.class);
        mountBookmarkablePage("/users.html", UserList.class);
        mountBookmarkablePage("/userform.html", UserForm.class);
        mountBookmarkablePage("/horarioform.html", HorarioForm.class);
        mountBookmarkablePage("/horarios.html", HorarioList.class);
        mountBookmarkablePage("/horarioschedules.html", HorarioScheduleList.class);
        mountBookmarkablePage("/logout.html", Logout.class);


        LoadDataManager loadDataManager = (LoadDataManager) getRequiredWebApplicationContext(this.getServletContext()).getBean("loadDataManager");
        loadDataManager.addAll();
    }

    protected void springInjection() {
        addComponentInstantiationListener(new SpringComponentInjector(this));
    }

    @Override
    protected Class<? extends AuthenticatedWebSession> getWebSessionClass() {
        return HorarioSession.class;
    }

    @Override
    protected Class<? extends WebPage> getSignInPageClass() {
        return Login.class;
    }


    @Override
    public Class getHomePage() {
        return Index.class;
    }

    //TODO: Mensagens

}